package com.fancy.learncenter.ui.activity;

import android.os.Bundle;
import android.widget.TextView;

import com.fancy.learncenter.R;
import com.fancy.learncenter.bean.BaseBean;
import com.fancy.learncenter.bean.MyMsgDataBean;
import com.fancy.learncenter.common.Constant;
import com.fancy.learncenter.net.CustomNetCallBack;
import com.fancy.learncenter.net.CustomNetSubscriber;
import com.fancy.learncenter.net.HttpMehtod;
import com.fancy.learncenter.ui.activity.base.BaseActivity;
import com.fancy.learncenter.utils.SPUtils;
import com.fancy.learncenter.utils.Utils;

import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import okhttp3.ResponseBody;
import retrofit2.Response;

import static com.fancy.learncenter.utils.NetUtil.getResResult;

public class MyMsgDetailActivity extends BaseActivity {

    @Bind(R.id.name)
    TextView name;
    @Bind(R.id.time)
    TextView time;
    @Bind(R.id.content)
    TextView content;

    int messageId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_msg_detail, Status.STATUS, "消息详情");
        ButterKnife.bind(this);

        name.setText(getIntent().getStringExtra("title"));
        time.setText(getIntent().getStringExtra("time"));
        content.setText(getIntent().getStringExtra("content"));
        messageId = getIntent().getIntExtra("messageId", 0);

        changeState();
    }

    @Override
    public void finish() {
        setResult(Constant.FRESH_RESULT_CALLBACK);
        super.finish();
    }

    private void changeState() {
        Map map = new HashMap();
        map.put("messageId", messageId);

        HttpMehtod.getInstance().changeMsgState(map, new CustomNetSubscriber(this) {
            @Override
            public void onNext(Response<ResponseBody> responseBodyResponse) {
                //解析数据
                BaseBean<MyMsgDataBean> baseBean = Utils.fromJsonObject(getResResult(responseBodyResponse), MyMsgDataBean.class);
                //数据业务逻辑处理
                CustomNetCallBack callBack = new CustomNetCallBack(getContext(), baseBean);
                callBack.setCallBack(new CustomNetCallBack.NetCallBack<MyMsgDataBean>() {
                    @Override
                    public void success(MyMsgDataBean dataBean) {

                    }

                    @Override
                    public void fail(String errorCode) {

                    }


                }).dealData();
            }

            @Override
            public void onCompleted() {
                super.onCompleted();
            }
        });
    }
}
